<template>
	<view>
		<cu-custom v-if="isdh" bgColor="bg-gradual-fff">
			<block slot="content">我的</block>
		</cu-custom>
		<u-loading-page :loading="true" loading-text="loading..." v-if="showLoading"></u-loading-page>
		<view v-show="!showLoading">
			<view class="viewbox"></view>
			<view class="index_banner" :style="'background-image:url('+user_bj+');'">
				<view class="user_a" v-if="user_info">
					<view class="user_a_a">
						<custom-image :lazy-load="true" width="120rpx" height="120rpx" radius="50%" lazy-load :src="user_info.avatar"></custom-image>
					</view>
					<view class="user_a_b">
						<view class="user_a_b_a">
							<view class="user_a_b_a_a">{{user_info.username?user_info.username:user_info.nickname}}</view>
							<view class="user_a_b_a_b" :style="'background-image:url('+user_info.level.level_img+');'" v-if="user_info.level.level_id>0">{{user_info.level.level_name}}</view>
						</view>
						<view class="user_a_b_b" v-if="user_info.level.level_id==0">{{user_info.mobile}}</view>
						<view class="user_a_b_b" v-if="user_info.level.level_id>0">{{user_info.vip_time}}到期</view>
					</view>
					<view class="user_a_c" @click="goPage('/pages/user/settings')">
						<view class="user_a_c_a" :style="'background-image:url('+user_10+');'"></view>
					</view>
				</view>
				<view class="user_a" @click="isLogin_click()" v-else>
					<view class="user_a_a">
						<custom-image :lazy-load="true" width="120rpx" height="120rpx" radius="50%" lazy-load :src="avatar_logo"></custom-image>
					</view>
					<view class="user_a_b">
						<view class="user_a_b_a" style="margin-top: 0;height: 120rpx; line-height: 120rpx;font-size: 30rpx;font-weight: bold;">登录/注册</view>
					</view>
				</view>
				<view class="l_bg" style="width: 710rpx;">
					<view class="bor_jb">
						<view class="l_cen">
							<view class="l_top">
								<view class="l_bottom">
									<view class="user_f">
										<view class="user_f_a" @click="goPage('/pages/user/user_income')">
											<view class="user_f_a_a">{{user_info?user_info.earnings:'-'}}</view>
											<view class="user_f_a_b">收益</view>
										</view>
										<!-- <view class="user_f_a" @click="goPage('/pages/user/user_recharge')">
											<view class="user_f_a_a">{{user_info?user_info.user_money:'-'}}</view>
											<view class="user_f_a_b">余额(元)</view>
										</view> -->
										<view class="user_f_a" @click="goPage('/pages/user/coupon')">
											<view class="user_f_a_a">{{user_info?user_info.coupon:'-'}}</view>
											<view class="user_f_a_b">优惠券</view>
										</view>
										<view class="user_f_a" @click="goPage('/pages/user/user_integral_log?source_type=2')">
											<view class="user_f_a_a">{{user_info?user_info.user_integral:'-'}}</view>
											<view class="user_f_a_b">积分</view>
										</view>
									</view>
								</view>
							</view>
						</view>
					</view>
				</view>
				<view class="user_e" :style="'background-image:url('+(!user_info || user_info.level.level_id==0?user_vip_bj:user_info.level.background_image)+');'" @click="goPage('/pages/user/user_vip')">
					<view class="user_e_a">
						<image :src="user_8"></image>
					</view>
					<view class="user_e_b" v-if="!user_info || user_info.level.level_id==0">
						<view class="user_e_b_a">开通会员·豪礼享不停</view>
						<view class="user_e_b_b">畅学海量精品课程  下单享优惠</view>
					</view>
					<view class="user_e_b" v-if="user_info.level.level_id>0">
						<view class="user_e_b_a">{{user_info.level.level_name}}</view>
						<view class="user_e_b_b">{{user_info.vip_time}}</view>
					</view>
					<view class="user_e_c">{{user_info.level.level_id>0?'续费':'开通会员'}}</view>
				</view>
				<view class="l_bg" style="width: 710rpx;margin-top: 20rpx;">
					<view class="bor_jb">
						<view class="l_cen">
							<view class="l_top">
								<view class="l_bottom">
									<view class="user_d">
										<view class="user_da">订单</view>
										<view class="user_db">
											<view class="user_d_a" style="width: 33.33%;height: 167rpx;"  @click="goPage('/pages/order/order')">
												<view class="user_d_a_a" :style="'background-image:url('+user_1+');background-size: 92rpx 92rpx;line-height: 285rpx;'">商城订单</view>
											</view>
											<view class="user_d_a" style="width: 33.33%;height: 167rpx;"  @click="goPage('/pages/curriculum_order/curriculum_order')">
												<view class="user_d_a_a" :style="'background-image:url('+user_2+');background-size: 92rpx 92rpx;line-height: 285rpx;'">课程订单</view>
											</view>
											<view class="user_d_a" style="width: 33.33%;height: 167rpx;"  @click="goPage('/pages/post_sale/post_sale')">
												<view class="user_d_a_a" :style="'background-image:url('+user_9+');background-size: 92rpx 92rpx;line-height: 285rpx;'">个性测试订单</view>
											</view>
										</view>
									</view>
								</view>
							</view>
						</view>
					</view>
				</view>
				<view class="l_bg" style="width: 710rpx;margin-top: 20rpx;">
					<view class="bor_jb">
						<view class="l_cen">
							<view class="l_top">
								<view class="l_bottom">
									<view class="user_d">
										<view class="user_da">其他功能</view>
										<view class="user_db">
											<view class="user_d_a" style="width: 20%;" @click="goPage('/pages/user/share')">
												<view class="user_d_a_a" :style="'background-image:url('+user_3+');'">邀请推广</view>
											</view>
											<view class="user_d_a" style="width: 20%;" @click="goPage('/pages/user_address/user_address')">
												<view class="user_d_a_a" :style="'background-image:url('+user_4+');'">收货地址</view>
											</view>
											<view class="user_d_a" style="width: 20%;"  @click="goPage('/pages/notice/info?id=4')">
												<view class="user_d_a_a" :style="'background-image:url('+user_5+');'">公司介绍</view>
											</view>
											<view class="user_d_a" style="width: 20%;"  @click="goPage('/pages/user/feedback')">
												<view class="user_d_a_a" :style="'background-image:url('+user_6+');'">建议反馈</view>
											</view>
											<button open-type="contact" class="user_d_a" style="width: 20%;">
												<view class="user_d_a_a" :style="'background-image:url('+user_7+');'">咨询客服</view>
											</button>
										</view>
									</view>
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<u-tabbar
			:value="value1"
			:fixed="true"
			:border="false"
			:placeholder="true"
			:safeAreaInsetBottom="true"
			activeColor="#462981"
			inactiveColor="#9583BA"
			zIndex='99'
			@change="tabbar_change"
		>
			<u-tabbar-item text="首页" :icon="value1==0?'/static/tabbar_11.png':'/static/tabbar_1.png'" ></u-tabbar-item>
			<u-tabbar-item text="订单" :icon="value1==1?'/static/tabbar_22.png':'/static/tabbar_2.png'" ></u-tabbar-item>
			<u-tabbar-item text="购物车" :icon="value1==2?'/static/tabbar_33.png':'/static/tabbar_3.png'" ></u-tabbar-item>
			<u-tabbar-item text="我的" :icon="value1==3?'/static/tabbar_44.png':'/static/tabbar_4.png'" ></u-tabbar-item>
		</u-tabbar>
	</view>
</template>
<script>
import request from '@/common/request.js';
import storage from '@/common/storage.js';
export default {
	data() {
		return {
			showLoading:true,
			value1:3,
			chat_num:0,
			isdh:false,
			avatar_logo:request.baseUrl_img+'/img/avatar.png',
			user_1:request.baseUrl_img+'/img/user_1.png',
			user_2:request.baseUrl_img+'/img/user_2.png',
			user_3:request.baseUrl_img+'/img/user_3.png',
			user_4:request.baseUrl_img+'/img/user_4.png',
			user_5:request.baseUrl_img+'/img/user_5.png',
			user_6:request.baseUrl_img+'/img/user_6.png',
			user_7:request.baseUrl_img+'/img/user_7.png',
			user_8:request.baseUrl_img+'/img/user_8.png',
			user_9:request.baseUrl_img+'/img/user_9.png',
			user_10:request.baseUrl_img+'/img/user_10.png',
			user_bj:request.baseUrl_img+'/img/user_bj.png',
			user_vip_bj:request.baseUrl_img+'/img/user_vip_bj.png',
			uid:0,
			img_list:[],
			distribution_code:'',
			share_img:'',
			share_content:'',
			share_name:'',
			user_info:''
		}
	},
	onShareAppMessage(res) { //发送给朋友
		return {
			title:this.share_name,
			path:'/pages/home/vendor?distribution_code='+this.distribution_code,
			imageUrl:this.share_img,
			desc:this.share_content,
			content:this.share_content
		}
	},
	onShareTimeline(res) {//分享到朋友圈
		return {
			title:this.share_name,
			path:'/pages/home/vendor?distribution_code='+this.distribution_code,
			imageUrl:this.share_img,
			desc:this.share_content,
			content:this.share_content
		}
	},
	onPageScroll: function(e) { //监听页面滚动
	     let that = this;
	     //判断你滑动的高度大于你元素距离顶部的高度值
	     if (e.scrollTop > 20){
	        //固定
		     that.isdh =true;
	     } else {
		     that.isdh = false;
	     }
	},
	onShow(){
		this.uid=uni.getStorageSync('uid');
		this.distribution_code=storage.currentUser.distribution_code;
		if(this.uid){
			this.user_click();
		}else{
			this.user_info='';
			this.showLoading=false;
		}
	},
	mounted() {
		this.share_config_post();
	},
	methods: {
		share_config_post(){
			let paramsList = {
				uid:this.uid
			}
			let optsList = {
				url: 'p-share_config',
				method: 'post'
			};
			let _this=this;
			request.httpRequest(optsList, paramsList).then(res => {
				if(res.data.code == 200){
					_this.share_img=this.baseUrl_img+res.data.data.share_img
					_this.share_content=res.data.data.share_content;
					_this.share_name=res.data.data.share_name;
				}
			});
		},
		user_click(){
			let paramsList = {
				'uid':this.uid
			}
			let optsList = {
				url: 'u-role_config',
				method: 'post'
			};
			let _this=this;
			request.httpTokenRequest(optsList, paramsList).then(res => {
				uni.hideLoading();
				if(res.data.code == 200){
					_this.user_info=res.data.data;
				}else{
					uni.removeStorageSync('uid');
				}
				_this.showLoading=false;
			});
			
		},
		goPage(url) {
			if (!this.$util.isLogin()) {
				return;
			}
			uni.navigateTo({
				url
			});
		},
		isLogin_click() {
			uni.removeStorageSync('uid');
			if (!this.$util.isLogin()) {
				return;
			}
		},
		ad_click(e){
			// let ad_info=this.index_banner[e];
			// if(ad_info.type==1){
			// 	uni.navigateTo({
			// 		url: '/pages/goods/info?id='+ad_info.unionid
			// 	})
			// 	return;
			// }else if(ad_info.type==2){
			// 	uni.navigateTo({
			// 		url: '/pages/mentor/info?mentor_id='+ad_info.unionid
			// 	})
			// 	return;
			// }else if(ad_info.type==9){
			// 	uni.navigateTo({
			// 		url: '/pages/webview/webview?url=' + ad_info.unionid
			// 	});
			// 	return;
			// }
		},
		tabbar_change(e){
			if (e == '0') {
				uni.reLaunch({
					url: '/pages/home/vendor'
				})
				return;
			}else if (e == '1') {
				uni.reLaunch({
					url: '/pages/order/order'
				})
				return;
			}else if (e == '2') {
				uni.reLaunch({
					url: '/pages/cart/list'
				})
				return;
			}else if (e == '3') {
				uni.reLaunch({
					url: '/pages/user/info'
				})
				return;
			}
		},
	}
}
</script>

<style  lang="scss" scoped>
	.user_e{
		width: 710rpx;
		height: 170rpx;
		margin: auto;
		margin-top: 20rpx;
		padding:34rpx 32rpx;
		overflow: hidden;
		background-position: center;
		background-repeat: no-repeat;
		background-size: 710rpx 170rpx;
	}
	.user_e_a{
		width: 102rpx;
		height:102rpx;
		float: left;
	}
	.user_e_a image{
		width: 100%;
		height: 100%;
	}
	.user_e_b{
		float: left;
		margin-left: 20rpx;
		height: 120rpx;
	}
	.user_e_b_a{
		font-family: Source Han Sans;
		font-size:36rpx;
		font-weight: 500;
		line-height: 65rpx;
		letter-spacing: 0px;
		color: #FFFFFF;
	}
	.user_e_b_b{
		font-family: Source Han Sans;
		font-size: 24rpx;
		font-weight: normal;
		line-height: 36rpx;
		color: rgba(255, 255, 255, 0.8);
	}
	.user_e_c{
		width: 146rpx;
		height: 50rpx;
		border-radius: 200rpx;
		background-color:#734FB5;
		float: right;
		text-align: center;
		font-family: Source Han Sans;
		font-size: 24rpx;
		font-weight: 350;
		line-height: 50rpx;
		/* 舌诊主色 */
		color: #fff;
		margin-top: 30rpx;
	}
	.user_f{
		width: 710rpx;
		height: auto;
		margin: auto;
		overflow: hidden;
		border-radius: 10rpx;
		padding: 30rpx;
	}
	.user_f_a{
		width: 33.33%;
		float: left;
		overflow: hidden;
	}
	.user_f_a_a{
		font-family: Source Han Sans;
		font-size: 32rpx;
		font-weight: 500;
		line-height: 80rpx;
		color: #fff;
		width: 100%;
		text-align: center;
	}
	.user_f_a_b{
		font-family: Source Han Sans;
		font-size: 26rpx;
		font-weight: normal;
		line-height: 32rpx;
		/* 中性色/333 */
		color: #fff;
		width: 100%;
		text-align: center;
	}
	button::after{
		border: 0;
	}
	button{
		background-color:inherit;
		padding-left: 0;
		padding-right: 0;
	}
	.index_banner{
		width: 750rpx;
		height:auto;
		background-repeat: no-repeat;
		background-position: top;
		background-size:100%;
		overflow: hidden;
		padding-bottom: 60rpx;
	}
	.user_a{
		overflow: hidden;
		position: relative;
		margin: auto;
		z-index: 7;
		width: 710rpx;
		padding: 40rpx 0;
		margin-top: 180rpx;
	}
	.user_a_a{
		width:120rpx;
		height: 120rpx;
		border-radius: 50%;
		overflow: hidden;
		float: left;
	}
	.user_a_b{
		float: left;
		margin-left: 30rpx;
		overflow: hidden;
		color: #fff;
		font-size: 30rpx;
	}
	.user_a_b_a{
		overflow: hidden;
		margin-top: 15rpx;
	}
	.user_a_b_a_a{
		font-family: PingFang SC;
		font-weight: 500;
		font-size: 30rpx;
		color: #fff;
		float: left;
		line-height: 46rpx;
	}
	.user_a_b_a_b{
		border-radius: 20rpx;
		width:auto;
		height: 40rpx;
		font-family: PingFang SC;
		font-weight: 500;
		font-size: 22rpx;
		color:#C6A8FF;
		float: left;
		margin-left: 20rpx;
		background-color: #442E66;
		line-height: 40rpx;
		padding:0 18rpx;
		background-repeat: no-repeat;
		background-position: left;
		background-size: 36rpx;
		padding-left: 40rpx;
	}
	.user_a_b_b{
		font-family: PingFang SC;
		font-weight: 500;
		font-size: 24rpx;
		color: #fff;
		margin-top: 20rpx;
	}
	.user_a_c{
		float: right;
		width: 120rpx;
		text-align: center;
	}
	.user_a_c_a{
		background-position: center;
		background-repeat: no-repeat;
		background-size: 41rpx 37rpx;
		width: 120rpx;
		height: 120rpx;
	}
	.user_a_c_b{
		font-size: 32rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #FFFFFF;
		margin-top: 20rpx;
	}
	.user_d{
		width: 710rpx;
		height:auto;
		border-radius:10rpx;
		padding:20rpx;
		overflow: hidden;
		margin: auto;
	}
	.user_d_a{
		width: 33.33%;
		float: left;
		height: 167rpx;
		overflow: hidden;
	}
	.user_d_a_a{
		background-position:center 15rpx;
		background-repeat: no-repeat;
		background-size: 80rpx 80rpx;
		font-family: PingFang SC;
		font-weight: 500;
		font-size: 26rpx;
		color: #fff;
		line-height: 260rpx;
		text-align: center;
	}
	.user_da{
		font-family: PingFang SC;
		font-weight: 800;
		font-size: 30rpx;
		color: #fff;
	}
	.user_db{
		overflow: hidden;
		margin-top: 20rpx;
	}
	.user_c{
		width: 710rpx;
		height: 150rpx;
		background: #FFFFFF;
		border-radius: 20rpx;
		margin: auto;
		margin-top: 20rpx;
		padding: 40rpx;
	}
	.user_c_a{
		width: 50%;
		float: left;
		line-height: 70rpx;
		background-position: left;
		background-repeat: no-repeat;
		background-size: 70rpx;
		font-family: PingFang SC;
		font-weight: 500;
		font-size: 28rpx;
		color: #333333;
		padding-left: 85rpx;
		text-align: left;
	}
	.index_b{
		width: 710rpx;
		height: 300rpx;
		margin: auto;
		margin-top: 20rpx;
		border-radius: 20rpx;
		overflow: hidden;
	}
</style>
